﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Com.DA;
using Com.BU;
using System.Media;

namespace Com.GUI.LibraryManager.Controls.SubControl
{
    /// <summary>
    /// Interaction logic for ucAirCeilingStructure.xaml
    /// </summary>
    public partial class ucAirCeilingStructure : UserControl
    {
        bool display = true;
        public ucAirCeilingStructure()
        {
            InitializeComponent();
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            loadData();
        }

        public void loadData()
        {
            cbxCeilingStructure.ItemsSource = LibraryManagerInCom.CeilingList;
            cbxCeilingStructure.DisplayMemberPath = "description";
            cbxCeilingStructure.SelectedIndex = 0;
        }
        public void reloadData()
        {
            cbxCeilingStructure.ItemsSource = null;
            cbxCeilingStructure.Items.Clear();
            foreach (var item in LibraryManagerInCom.CeilingList)
            {
                cbxCeilingStructure.Items.Add(item);
            }
            cbxCeilingStructure.DisplayMemberPath = "description";
            cbxCeilingStructure.SelectedIndex = 0;
        }

        private void cbxCeilingStructure_SelectionChanged(object sender, SelectionChangedEventArgs e)
    
        {
            try
            {
                if (display)
                {
                    txtID.Text = ((tb_ceiling)cbxCeilingStructure.SelectedItem).id.ToString();
                }
            }
            catch (Exception)
            {
                
            }

        }

        public void addNew()
        {
            display = false;
            txtID.Text = (LibraryManagerInCom.CeilingList.Count() + 1).ToString();
            cbxCeilingStructure.Text = "";
        }
        public void saveData()
        {
            tb_ceiling cl = new tb_ceiling();
            cl.description = cbxCeilingStructure.Text;
            LibraryManagerInCom.addCeiling(cl);
            reloadData();
        }
        public void deleteData()
        {
            tb_ceiling cl = (tb_ceiling)cbxCeilingStructure.SelectedItem;
            LibraryManagerInCom.deleCeiling(cl);
            reloadData();
        }
        public void copyData()
        {
            tb_ceiling cl = (tb_ceiling)cbxCeilingStructure.SelectedItem;
            tb_ceiling cl2 = LibraryManagerInCom.copyCeiling(cl);
            cbxCeilingStructure.Text = cl2.description;
            txtID.Text = (LibraryManagerInCom.CeilingList.Count() + 1).ToString();
        }
    }
}
